package ru.qrck.quitetaskmanager;

import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;

public class ProcessInfoTable {
	
	class ProcessInfo
	{
		public String name = null;
		public String pkgName = null;
		public int pid = 0;
		public ArrayList<String> services = new ArrayList<String>(); // services running inside the process
		
		public ProcessInfo(int p) {
			pid = p;
		}
	};
	
	// Map between Process ID and the process package name
	private Map<Integer, ProcessInfo> mProcessMap = new TreeMap<Integer, ProcessInfo>();
		
	///////////////////////////// IMPL ////////////////////////////	
	
	public ProcessInfo get(int pid) {
		return mProcessMap.get(new Integer(pid));
	}
	
	public void setProcessName(int pid, String name) {
		ProcessInfo pi = mProcessMap.get(new Integer(pid));
		if (pi == null)
			pi = new ProcessInfo(pid);
		pi.name = name;
		mProcessMap.put(pid, pi);
	}

	public String getProcessName(int pid) {
		ProcessInfo pi = mProcessMap.get(new Integer(pid));
		if (pi != null)
			return pi.name;
		return null;
	}
	
	
/*	public void setProcessViewExpanded(int pid, boolean val) {
		ProcessInfo pi = mProcessMap.get(new Integer(pid));
		if (pi == null)
			pi = new ProcessInfo(pid);
		pi.expanded = val;
		mProcessMap.put(pid, pi);
	}

	public boolean getProcessViewExpanded(int pid) {
		ProcessInfo pi = mProcessMap.get(new Integer(pid));
		if (pi == null)
			return false;
		return pi.expanded;
	} */

	public void setProcessPkgName(int pid, String name) {
		ProcessInfo pi = mProcessMap.get(new Integer(pid));
		if (pi == null)
			pi = new ProcessInfo(pid);
		pi.pkgName = name;
		mProcessMap.put(pid, pi);
	}
	
	public String getProcessPkgName(int pid) {
		ProcessInfo pi = mProcessMap.get(new Integer(pid));
		if (pi != null)
			return pi.pkgName;
		return null;
	}

	public void addProcessService(int pid, String name) {		
		if (pid != 0) {		
			ProcessInfo pi = mProcessMap.get(new Integer(pid));
			if (pi == null)
				pi = new ProcessInfo(pid);
			pi.services.add(name);
			mProcessMap.put(pid, pi);
		} 
	}
	

	public void clearProcessMap() {
		mProcessMap.clear();
	}

}
